package network;

import java.util.*;
import bundle.*;

public class ResendTask extends TimerTask {

	public synchronized void run() {
		//for (String s : NetworkLayer.bellman.resend) {
		for (String s : BundleLayer.warehouse.storage.keySet()) {
			if (BundleLayer.warehouse.storage.containsKey(s)) {
				System.err.println("Found messages to resend to " + s);
				LinkedList<String> liste = BundleLayer.warehouse.get(s)
						.getMessages(); // This method should return
				// chronologically ordered messages
				for (String m : liste) {
					NetworkLayer.send(m); // In case of retransmission failure,
					// time is reset for now.
				}
			}
		}
		NetworkLayer.bellman.resend = new LinkedList<String>();
		BundleLayer.cleanBundleStorage();
	}

}